Getters and Setters: Code smell, Necessary Evil, or Can't Live Without Them [closed]

Posted by Avery Payne on Stack Overflow See other posts from Stack Overflow or by Avery Payne
Published on 2009-06-21T01:49:57Z Indexed on 2010/03/22 23:41 UTC
Read the original article Hit count: 272

Possible Duplicate:
Allen Holub wrote “You should never use get/set functions”, is he correct?

Is there a good, no, a very good reason, to go through all the trouble of using getters and setters for object-oriented languages? What's wrong with just using a direct reference to a property or method? Is there some kind of "semantical coverup" that people don't want to talk about in polite company? Was I just too tired and fell asleep when someone walked out and said "Thou Shalt Write Copious Amounts of Code to Obtain Getters and Setters"?


Follow-up after a year:

It seems to be a common occurrence with Java, less so with Python. I'm beginning to wonder if this is more of a cultural phenomena (related to the limitations of the language) rather than "sage advice".

The -1 question score is complete for-the-lulz as far as I am concerned. It's interesting that there are specific questions that are downvoted, not because they are "bad questions", but rather, because they hit someone's raw nerve.

© Stack Overflow or respective owner

Related posts about object-oriented-design